﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

namespace ExpiredDomainSearch
{
    public partial class FormContact : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnContact_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("info@gmail.com");
                mail.To.Add(txtEmail.Text);
                mail.Subject = "Contact form submitted";
                mail.Body = txtMessage.Text;

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Main send to site admin. We will reply you soon');", true);
            }
            catch
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Error sending mail');", true);
            }
        }
    }
}